package com.example;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class Sonarqube_test {

    private String unreadField;

    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("apple");
        list.add("banana");
        list.add("orange");

        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }

        try {
            int result = divide(10, 0); // Division by zero
            System.out.println("Result: " + result);
        } catch (ArithmeticException e) {
            System.out.println("Cannot divide by zero!");
        }

        // Potential null pointer dereference
        printLength(null);

        // Dead code example
        if (false) {
            System.out.println("This will never be printed");
        }

        // Unused variable
        String unused = "This variable is never used";

        // Dead local store
        int deadStore = 42;

        // Unclosed resource
        try {
            FileInputStream fis = new FileInputStream("test.txt");
            // Do something with fis
        } catch (IOException e) {
            e.printStackTrace();
        }

        // Infinite recursion
        recursiveMethod();
    }

    // Method to perform division
    private static int divide(int x, int y) {
        return x / y;
    }

    // Method with potential null pointer dereference
    private static void printLength(String str) {
        System.out.println(str.length());
    }

    // Method with infinite recursion
    private static void recursiveMethod() {
        recursiveMethod();
    }
}